/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q0409.java
 * @Author : WangRuoyu
 * @Date 2023/1/12 16:45
 */

package leetcode;

import java.util.HashMap;

public class Q0409 {
    public int longestPalindrome(String s) {
        if (s.length() == 1) {
            return 1;
        }
        int res = 0;

        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            map.put(s.charAt(i), map.getOrDefault(s.charAt(i), 0) + 1);
        }

        boolean a = false;
        for (Integer value : map.values()) {
            if (value % 2 == 0) {
                res += value;
            } else {
                if (!a) {
                    res += value;
                    a = true;
                } else {
                    res += value - 1;
                }
            }
        }

        return res;
    }

    public static void main(String[] args) {
        Q0409 sl = new Q0409();
        String s = "ccc";
        System.out.println(sl.longestPalindrome(s));
    }
}
